package com.dxf.chepter05;

public class T59_java动态绑定 {
    public static void main(String[] args) {
        AA obj = new BB();
        //java 动态绑定机制小结:
        //1 如果调用方法,jvm会将该方法和对象的内存地址绑定
        //2 如果调用属性,没有动态绑定机制
        System.out.println(obj.sum());//40    30
        System.out.println(obj.sum1());//30   20

    }
}


class AA{
    public int i = 10;
    public int sum(){
        return getI()+10;  //getI() 还是找BB中是否存在getI()方法,动态绑定 --> jvm会将该方法和对象的内存地址绑定
    }

    public int sum1(){
        return i+10;
    }

    public int getI(){
        return i;
    }
}

class BB extends AA{
    public int i = 20;
 /*   public int sum(){
        return i+20;
    }*/

  /*  public int sum1(){
        return i+10;
    }
*/
    public int getI(){
        return i;
    }


}